<template>
  <div class="list">
    <ul>
      <li v-for="item in list" :key="item.articleId" class="list-item" @click="enter(item.articleId)">
        <div class="left-content">
          <div class="item-title">
            {{ item.articleTitle }}
          </div>
          <div class="item-content">
            {{ item.articleText }}
          </div>
          <div class="content-bottom">
            <span>{{ item.userName }}</span>
            <span>
              <svg-icon icon-class="message1" />
              2</span>
            <span>
              <svg-icon icon-class="heart" />
              30</span>
          </div>
        </div>
        <div class="right">
          <img src="https://upload-images.jianshu.io/upload_images/14106711-1596db994364fc21.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/360/h/240" alt="">
        </div>
      </li>
    </ul>
    <div class="load-more" @click="getList">阅读更多</div>
  </div>
</template>

<script>
import { getIndexList } from '@/api/index.js'
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      list: [],
      page: 0
    }
  },
  computed: {
    ...mapGetters(['userId'])
  },
  mounted() {
    this.getList()
  },
  methods: {
    // 得到列表
    getList() {
      var data = {
        page: this.page
      }
      getIndexList(data).then(response => {
        console.log(response)
        this.list = this.list.concat(response.data.result.reverse())
        this.page++
      })
    },
    // 文章详情
    enter(id) {
      console.log(id)
      this.$router.push({
        path: '/detail/' + id
      })
    }
  }
}
</script>

<style scoped lang="stylus">
  .list
    padding: 5px 10px
    margin: 0 20px
    border-top: 1px solid #eee
    .list-item
      list-style-type: none
      height: 145px
      margin: 5px
      // min-height: 100px
      width: 100%
      margin-bottom: 20px
      border-bottom: 1px solid #f0f0f0
      position: relative
      .left-content
        width: 580px
        padding-right: 175px
        float: left
        .item-title
          font-weight: bold
          font-size: 18px
          margin-bottom: 13px
          &:hover
            text-decoration: underline
            cursor: pointer
        .item-content
          font-size: 13px
          color: #999
          text-indent: 2em
          overflow: hidden
          max-height: 72px
          line-height: 24px
          text-overflow: ellipsis
        .content-bottom
          font-size: 11px
          color: #999
          margin-top: 10px
          & span:nth-child(2)
            margin-left: 10px
            vertical-align: middle
          & span:nth-child(3)
            margin-left: 10px
      .right
        position: absolute
        right: 0
        top: 50%
        margin-top: -50px
        width: 150px
        & img
          border-radius: 5px
          width: 100%
  .load-more
    width: 100%
    margin-bottom: 10px
    text-align: center
    background: #939292
    opacity: 0.8
    border-radius: 50px
    color: #fff
    cursor: pointer
    font-size: 15px
    padding: 10px 10px
    &:hover
      opacity: 1
</style>
